doc: remove extensionless CJS exception for type:module#62176
doc: remove extensionless CJS exception for type:module#62176nodejs-github-bot merged 4 commits intonodejs:mainfrom
Conversation
Remove the documented exception that extensionless files in type: "module" packages are recognized as CommonJS when included via require(). This exception conflicted with the ESM resolution specification which states that extensionless files within a package scope with an explicit type field follow the format of the type field. The behavior on main already matches the ESM spec since nodejs#61600, this change aligns the CJS documentation accordingly. Refs: nodejs#61600 Refs: nodejs#62083
|
Review requested:
|
doc/api/modules.md
Outdated
| [`"type"`][] with a value of `"module"`, those files will be recognized as | ||
| CommonJS modules only if they are being included via `require()`, not when | ||
| used as the command-line entry point of the program). | ||
| [`"type"`][] with a value of `"module"`, those files will not be recognized as |
There was a problem hiding this comment.
I think we can just removed this entire point, because the opening paragraph says:
Node.js will treat the following as CommonJS modules
Instead, just add a new paragraph noting that files with extensions outside that set/files without extensions would be treated based on the type field in the package.json
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
|
@GeoffreyBooth I merged your edits. |
I think something is buggy with the GitHub suggestions feature, because it looks like my suggestion got appended after the old text rather than replacing it:
|
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
|
@GeoffreyBooth ptal |
GeoffreyBooth
left a comment
There was a problem hiding this comment.
Okay so just to confirm, in 26.0.0+:
- There are no more weird exceptions for extensionless files: they behave identically to
.jsfiles whether in atype: 'module'scope, atype: 'commonjs'scope, or a scope where there’s notypefield. - Syntax detection only ever applies within a scope where there’s no
typefield.
Is this correct?
Commit Queue failed- Loading data for nodejs/node/pull/62176 ✔ Done loading data for nodejs/node/pull/62176 ----------------------------------- PR info ------------------------------------ Title doc: remove extensionless CJS exception for type:module (#62176) Author Matteo Collina <matteo.collina@gmail.com> (@mcollina) Branch mcollina:doc/remove-extensionless-cjs-exception -> nodejs:main Labels doc, module, semver-major Commits 4 - doc: remove extensionless CJS exception for type:module packages - Update modules.md - doc: fix duplicated wording in modules.md - Update doc/api/modules.md Committers 2 - Matteo Collina <hello@matteocollina.com> - GitHub <noreply@github.com> PR-URL: https://github.com/nodejs/node/pull/62176 Refs: https://github.com/nodejs/node/pull/61600 Refs: https://github.com/nodejs/node/pull/62083 Refs: https://github.com/nodejs/node/issues/61971 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/62176 Refs: https://github.com/nodejs/node/pull/61600 Refs: https://github.com/nodejs/node/pull/62083 Refs: https://github.com/nodejs/node/issues/61971 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 10 Mar 2026 07:10:06 GMT ✔ Approvals: 3 ✔ - Geoffrey Booth (@GeoffreyBooth): https://github.com/nodejs/node/pull/62176#pullrequestreview-4059937547 ✔ - Ulises Gascón (@UlisesGascon): https://github.com/nodejs/node/pull/62176#pullrequestreview-3994329997 ✔ - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/62176#pullrequestreview-4060635747 ✘ semver-major requires at least 2 TSC approvals ✔ Last GitHub CI successful ℹ Green GitHub CI is sufficient -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/24124327533 |
Commit Queue failed- Loading data for nodejs/node/pull/62176 ✔ Done loading data for nodejs/node/pull/62176 ----------------------------------- PR info ------------------------------------ Title doc: remove extensionless CJS exception for type:module (#62176) Author Matteo Collina <matteo.collina@gmail.com> (@mcollina) Branch mcollina:doc/remove-extensionless-cjs-exception -> nodejs:main Labels doc, module, semver-major Commits 4 - doc: remove extensionless CJS exception for type:module packages - Update modules.md - doc: fix duplicated wording in modules.md - Update doc/api/modules.md Committers 2 - Matteo Collina <hello@matteocollina.com> - GitHub <noreply@github.com> PR-URL: https://github.com/nodejs/node/pull/62176 Refs: https://github.com/nodejs/node/pull/61600 Refs: https://github.com/nodejs/node/pull/62083 Refs: https://github.com/nodejs/node/issues/61971 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/62176 Refs: https://github.com/nodejs/node/pull/61600 Refs: https://github.com/nodejs/node/pull/62083 Refs: https://github.com/nodejs/node/issues/61971 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 10 Mar 2026 07:10:06 GMT ✔ Approvals: 4 ✔ - Geoffrey Booth (@GeoffreyBooth): https://github.com/nodejs/node/pull/62176#pullrequestreview-4059937547 ✔ - Ulises Gascón (@UlisesGascon): https://github.com/nodejs/node/pull/62176#pullrequestreview-3994329997 ✔ - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/62176#pullrequestreview-4060635747 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/62176#pullrequestreview-4073605376 ✔ Last GitHub CI successful ℹ Green GitHub CI is sufficient -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 62176 From https://github.com/nodejs/node * branch refs/pull/62176/merge -> FETCH_HEAD ✔ Fetched commits as 8a48913e1cd0..4b8b3c9ae834 -------------------------------------------------------------------------------- [main a6cb26bb09] doc: remove extensionless CJS exception for type:module packages Author: Matteo Collina <hello@matteocollina.com> Date: Tue Mar 10 08:09:38 2026 +0100 1 file changed, 2 insertions(+), 3 deletions(-) [main 930ee1a818] Update modules.md Author: Matteo Collina <matteo.collina@gmail.com> Date: Sun Mar 22 16:27:53 2026 +0100 1 file changed, 20 insertions(+), 1 deletion(-) [main a09ce3fa03] doc: fix duplicated wording in modules.md Author: Matteo Collina <hello@matteocollina.com> Date: Sun Mar 22 17:40:15 2026 +0100 1 file changed, 6 insertions(+), 27 deletions(-) [main 2deda1c3ae] Update doc/api/modules.md Author: Matteo Collina <matteo.collina@gmail.com> Date: Sun Apr 5 23:19:37 2026 +0200 1 file changed, 2 insertions(+) ✔ Patches applied There are 4 commits in the PR. Attempting autorebase. (node:378) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/8) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- doc: remove extensionless CJS exception for type:module packageshttps://github.com/nodejs/node/actions/runs/24125357599 |
|
Landed in ff08094 |
|
I don't think this was quite ready to land; my question above in #62176 (review) hasn't been answered. But if my assumptions there are correct then there's no need to revert. @aduh95 @mcollina |

The CJS documentation has included an exception since v16 (added in #41383) stating that extensionless files in
type: "module"packages are recognized as CommonJS when included viarequire(). This exception conflicts with the ESM resolution specification which states that extensionless files within a package scope with an explicittypefield follow the format of thetypefield.Since #61600, the behavior on
mainalready matches the ESM spec: extensionless files respect thetypefield. This change aligns the CJS documentation accordingly by removing the contradicting exception.For v25.x, #62083 restores the documented exception as a targeted fix to avoid breaking packages like yargs v17 that relied on the old behavior.
Refs: #61600
Refs: #62083
Refs: #61971